<?php

/**
 * This is the model class for table "personnel".
 *
 * The followings are the available columns in table 'personnel':
 * @property integer $id
 * @property string $last_name
 * @property string $first_name
 * @property string $middle_initial
 * @property string $birthdate
 * @property string $contact_number
 * @property string $date_hired
 * @property string $job_title
 * @property string $job_description
 * @property string $schedule
 * @property integer $available
 *
 * The followings are the available model relations:
 * @property Appointment[] $appointments
 */
class Personnel extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Personnel the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'personnel';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('last_name, first_name, date_hired, job_title, job_description, schedule, available', 'required'),
			array('available', 'numerical', 'integerOnly'=>true),
			array('last_name, first_name, job_title', 'length', 'max'=>150),
			array('middle_initial', 'length', 'max'=>5),
			array('contact_number', 'length', 'max'=>45),
			array('job_description, schedule', 'length', 'max'=>500),
			array('birthdate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, last_name, first_name, middle_initial, birthdate, contact_number, date_hired, job_title, job_description, schedule, available', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'appointments' => array(self::HAS_MANY, 'Appointment', 'personnel'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'last_name' => 'Last Name',
			'first_name' => 'First Name',
			'middle_initial' => 'Middle Initial',
			'birthdate' => 'Birthdate',
			'contact_number' => 'Contact Number',
			'date_hired' => 'Date Hired',
			'job_title' => 'Job Title',
			'job_description' => 'Job Description',
			'schedule' => 'Schedule',
			'available' => 'Available',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('middle_initial',$this->middle_initial,true);
		$criteria->compare('birthdate',$this->birthdate,true);
		$criteria->compare('contact_number',$this->contact_number,true);
		$criteria->compare('date_hired',$this->date_hired,true);
		$criteria->compare('job_title',$this->job_title,true);
		$criteria->compare('job_description',$this->job_description,true);
		$criteria->compare('schedule',$this->schedule,true);
		$criteria->compare('available',$this->available);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}